/*
 * Copyright 2007-2009 Perttu "celeron55" Ahola <celeron55@gmail.com>
 *
 * This file is part of jukuMagic.
 *
 * jukuMagic is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * jukuMagic is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with jukuMagic.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef circuit_h_
#define circuit_h_

#include "muut.h"
#include <vector>

struct PadsPart {
	string name; //esim. "R1"
	string footprint; //esim. "R025" tai "DIP 8 300"
	vector<int> circuitfootnums;
};

class Circuit{
private:
	vector<Part> parts;
	vector<WirePart> wireparts;
	vector<Connection> connections;
	bool connectionsfinalized;
	int maxfootnum;
	
	void FinalizeConnections();
	
public:
	Circuit();

	void ClearAll();
	
	void AddPart(Part part);
	bool Add1x1Part(string sname, int footnum, string footname);
	bool AddRowPart(string sname, vector<int> footnums, vector<string> footnames);
	bool AddDILPart(string sname, unsigned int milwidth,
			vector<int> footnums, vector<string> footnames);
	bool AddFixedLength2LeggedPart(string sname, int length,
			int footnum1, int footnum2, string footname1, string footname2);
	bool AddCustomFootprintPart(string sname, string footprint,
			vector<int> footnums, vector<string> footnames);

	void AddWirePart(WirePart wirepart);
	void AddWirePart(string sname, int maxlength,
			int footnum1, int footnum2, string foot1name, string foot2name);
	
	void AddConnection(Connection connection);

	bool AddPartFromKytString(string sname, string stype, string snumbers);

	bool AddPart(PadsPart padspart);

	bool LoadKytFile(string filename);
	bool LoadPadsFile(string filename);
	bool LoadFile(string filename);
	
	vector<Part> & Parts();
	vector<WirePart> & WireParts();
	vector<Connection> & Connections();

	vector<Part> * PartsP();
	vector<WirePart> * WirePartsP();
	vector<Connection> * ConnectionsP();
	
	vector<int> GetFootNumsConnectedDirectly(int footnum);
	void GetAllFootNumsConnected(int footnum, vector<int> *alreadysearched);
	vector<int> GetFootNumsConnected(int footnum);
	
	int FindPartNumWithFootNum(int num);
	int FindWirePartNumWithFootNum(int num);
	int MaxFootNum();
};


#endif

